Fix superblock IO error handling and add footer validation#889
Open
xiaoxichen wants to merge 2 commits into
Open
Fix superblock IO error handling and add footer validation#889xiaoxichen wants to merge 2 commits into
xiaoxichen wants to merge 2 commits into
Conversation
Collaborator
Author
|
@JacksonYao287 this is a replacement PR for #866 could you please take a review |
8ef07a3 to
7bf160a
Compare
This change improves superblock error handling and integrity checking: - Fail fast on IO errors during superblock read instead of treating them as fresh/unformatted disks - Add footer superblock validation for HDD devices to detect corruption - Check header and footer write errors independently to prevent silent failures - Add comprehensive unit tests covering all error scenarios Changes: - read_first_block(): Now throws std::system_error on IO errors instead of returning garbage data - write_super_block(): Separately validates header and footer writes with independent error checking - sanity_check(): New method that validates footer consistency on HDD devices by comparing header and footer superblocks using full memcmp - Added 6 unit tests covering IO errors, corruption detection, and footer validation scenarios Use release assert instead of exceptions for superblock IO errors Per review feedback, replace exception throws with HS_REL_ASSERT for all superblock IO errors to ensure immediate crash on failure: - read_first_block(): Use HS_REL_ASSERT instead of throwing std::system_error - sanity_check(): Use HS_REL_ASSERT for header/footer read errors and mismatch - Update tests from ASSERT_THROW to ASSERT_DEATH to verify crash behavior
7bf160a to
6dd7079
Compare
Collaborator
Author
|
@JacksonYao287 comment addressed |
JacksonYao287
previously approved these changes
Jun 5, 2026
On first boot (format_devices path), all devices have invalid headers on disk when PhysicalDev is constructed — before write_super_block is called. The original code blindly memcmp'd header vs footer on garbage data, causing a crash on HDD devices where mirror_super_block=1. In load_devices, a device with an invalid header goes to pdevs_to_format and then format_single_device. At that point m_first_blk_hdr (and thus m_pdev_info.system_uuid) is already populated from other valid devices in the cluster. So if the footer on disk is valid and its system_uuid matches, it means the footer survived but the header was corrupted — not a fresh device. If the footer uuid does not match (or footer is invalid), it is leftover/garbage data and safe to treat as first boot. New logic: - Header valid: compare header and footer as before - Header invalid, footer valid + uuid matches cluster: header corruption, assert - Otherwise: first boot / leftover data, skip validation
6dd7079 to
e28c0c0
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## stable/v7.x #889 +/- ##
==============================================
Coverage ? 48.35%
==============================================
Files ? 110
Lines ? 12971
Branches ? 6235
==============================================
Hits ? 6272
Misses ? 2565
Partials ? 4134 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change improves superblock error handling and integrity checking:
Changes:
Use release assert instead of exceptions for superblock IO errors
Per review feedback, replace exception throws with HS_REL_ASSERT for all superblock IO errors to ensure immediate crash on failure: